package com.xuecheng.content.controller;

import com.xuecheng.api.content.CourseAuditApi;
import com.xuecheng.api.content.model.dto.CourseBaseDTO;
import com.xuecheng.api.content.model.qo.QueryCourseModel;
import com.xuecheng.api.content.model.vo.CourseAuditVO;
import com.xuecheng.common.domain.page.PageRequestParams;
import com.xuecheng.common.domain.page.PageVO;
import com.xuecheng.content.convert.CourseBaseConvert;
import com.xuecheng.content.service.CourseBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 审核课程控制器
 *
 * @author lily
 * @date 2021/12/13
 */
@RestController
public class CourseAuditController implements CourseAuditApi {

    // 运营平台标识--可以查询所哟教学机构的数据
    public static final Long OPERATION_FLAG = -99887799L;

    @Autowired
    private CourseBaseService courseBaseService;

    /**
     * 运营平台查询课程列表
     *
     * @param params 分页参数
     * @param model  查询数据
     * @return {@link PageVO}
     *
     * 请求参数都封装进了请求的类中
     */
    @Override
    @PostMapping("m/course/list")
    public PageVO queryCourseList(PageRequestParams params, QueryCourseModel model) {

        // TODO TODO关于管理员登陆问题，后期应该是管理员账号，默认值为这个常量值
        PageVO pageVO = courseBaseService.queryCourseBaseList(params, model, OPERATION_FLAG);

        return pageVO;
    }


    /**
     * 课程审核(提交的课程才可审核)
     *
     * @param auditVO 审核结果
     * @author Lily
     * @date 2021/12/13 21:51
     * @paramType [com.xuecheng.api.content.model.vo.CourseAuditVO]
     * @description
     */
    @PostMapping("m/courseReview/approve")
    @Override
    public void approveCourse(@RequestBody CourseAuditVO auditVO) {

        // 将vo转成dto
        CourseBaseDTO courseBaseDTO = CourseBaseConvert.INSTANCE.vo2dto(auditVO);

        // 调用service方法审核
        courseBaseService.approve(courseBaseDTO);
    }
}
